home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Utilities / Installers / Smaller Installer 2.0 / Preinstalled version / Examples / Hook Procedure Examples / PasswordHook / PasswordHook.c next >
Encoding:
C/C++ Source or Header  |  1996-03-02  |  4.6 KB  |  161 lines  |  [TEXT/CWIE]

  1. /******************************************************************************
  2.     Smaller Installer © 1996 Bill Goodman, All Rights Reserved
  3. *******************************************************************************
  4.  
  5. Password Hook Example
  6.  
  7. This installer hook procedure prompts the user to enter a password when the
  8. INSTALL button is clicked. The password is specified in the "Password" field
  9. of the SI Builder project document and may be any string up to 255 characters
  10. in length.
  11.  
  12. To build this hook procedure, compile this code and create a code resource
  13. (Type:SICR, ID:501, non-preloaded, nonpurgeable, unlocked, unprotected,
  14. non-sysheap). Add this resource to the "PasswordHook.rsrc" file. Copy all the
  15. resources in "PasswordHook.rsrc" to your installer's resource file.
  16. ******************************************************************************/
  17.  
  18. // This file is compatible with version 2.1 of the universal headers
  19. #include <Dialogs.h>
  20.  
  21. #ifdef __MWERKS__
  22. #include <A4Stuff.h>
  23. #endif
  24.  
  25. #ifdef THINK_C
  26. #include <SetUpA4.h>
  27. #endif
  28.  
  29. #include "SIHookProc.h"
  30.  
  31.  
  32. /******************************************************************************
  33.     Module Internal Function Prototypes
  34. ******************************************************************************/
  35. void BeginOperationFunction(void);
  36.  
  37.  
  38. /******************************************************************************
  39.     Constant Definitions
  40. ******************************************************************************/
  41. // Dialog Definitions
  42. #define pswdDlg                500    // Password dialog
  43. #define ok_pswdlg                1        // OK button
  44. #define stop_pswdDlg            2        // STOP button
  45. #define password_pswdDlg    3        // Password edit text field
  46.  
  47. // Alert Definitions
  48. #define errorAlrt                510    // "This password is not valid. Please call 1-800-555-XXXX for assistance."
  49.  
  50.  
  51. /******************************************************************************
  52.     Module Variable Definitions
  53. ******************************************************************************/
  54. SIHookParmBlk *gParms;        // Global pointer to parameter block
  55. Str255 gPasswordStr;            // Password string
  56.  
  57.  
  58. /*****************************************************************************/
  59. pascal void main(
  60.         SIHookParmBlk *parmBlk    // Pointer to parameter block
  61.         )
  62. /******************************************************************************
  63.     This is the main entry point for the installer hook procedure.
  64. ******************************************************************************/
  65. {
  66. #ifdef __MWERKS__
  67. long holdA4;
  68. #endif
  69.  
  70. // Set up access to global variables
  71. #ifdef THINK_C
  72. RememberA0();
  73. SetUpA4();
  74. #endif
  75.  
  76. #ifdef __MWERKS__
  77. holdA4 = SetCurrentA4();
  78. #endif
  79.  
  80. gParms = parmBlk;
  81.  
  82. switch (gParms->function)
  83.     {
  84.     case siHookBeginOperation:
  85.         BeginOperationFunction();
  86.         break;
  87.     }
  88.  
  89. // Restore original A4 value
  90. #ifdef THINK_C
  91. RestoreA4();
  92. #endif
  93.  
  94. #ifdef __MWERKS__
  95. SetA4(holdA4);
  96. #endif
  97. }
  98.  
  99.  
  100. /*****************************************************************************/
  101. void BeginOperationFunction(void)
  102. /******************************************************************************
  103.     Input parameters:
  104.         "targetVRefNum"    Volume reference number of target volume
  105.         "groupAPFlags"        Groups currently selected
  106.         "groupQUSel"
  107.         "groupVZSel"
  108.         "group32Flags"
  109.         "group64Flags"
  110.         "group96Flags"
  111.         "groupEnvironFlags"
  112.         "passwordPtr"        Pointer to password string
  113.         "filesRemaining"    Number of files remaining to install or remove
  114.         "bytesRemaining"    Number of bytes of data remaining to install or remove
  115.         "doingRemove"        Non-zero if doing remove operation
  116.  
  117.     Returns:
  118.         "passwordPtr"        Pointer to password string
  119.         "result"                Hook result code (siHookNoErr, siHookQuit, siHookAbort)
  120.  
  121.     This function is called when the install button or the remove button is
  122.     clicked to begin installing or removing files.
  123. ******************************************************************************/
  124. {
  125.  
  126. DialogPtr dlgPtr;
  127. short itemType;
  128. Handle itemHdl;
  129. Rect itemRect;
  130. short item;
  131.  
  132. if (gParms->doingRemove)
  133.     return;    // Allow Remove to proceed
  134.  
  135. if (gParms->passwordPtr != NULL)
  136.     {    // Password error
  137.     StopAlert(errorAlrt, NULL);
  138.     gParms->result = siHookQuit;
  139.     gPasswordStr[0] = 0;    // Clear invalid password
  140.     return;
  141.     }
  142.  
  143. if (gPasswordStr[0])
  144.     gParms->passwordPtr = gPasswordStr;    // Use previously entered password
  145. else
  146.     {    // No previous password entered - prompt user for password
  147.     dlgPtr = GetNewDialog(pswdDlg, NULL, (WindowPtr) -1L);    
  148.     ModalDialog(NULL, &item);
  149.     if (item == stop_pswdDlg)
  150.         gParms->result = siHookAbort;    // User cancelled - force installer to abort
  151.     else
  152.         {
  153.         GetDItem(dlgPtr, password_pswdDlg, &itemType, &itemHdl, &itemRect);
  154.         GetIText(itemHdl, gPasswordStr);
  155.         gParms->passwordPtr = gPasswordStr;
  156.         }
  157.     DisposDialog(dlgPtr);
  158.     }
  159. return;
  160. }
  161.